// express获取请求体数据

const express = require('express');
const app = express();  //创建应用对象
const bodyParser = require('body-parser');

const jsonParse = bodyParser.json();
const urlencodedParse = bodyParser.urlencoded({extended: false});

// http://localhost:9020/login
app.get('/login', (req, res) => {
    res.sendFile(__dirname + '/20.express.bodyParse.html')
})

app.post('/login', urlencodedParse, (req, res) => {
    console.log(req.body);  //获取到数据
    res.send(res.body)
})

app.all('*', (req, res) => {
    res.end('404 Not Found')
})

app.listen(9020, () => {
    console.log('express server running at http://127.0.0.1:9020')
})